<?php


namespace app\user\controller;


use app\common\controller\Api;
use app\user\model\DetailModel;
use app\user\model\TermModel;

class Term extends Base
{
    protected $noNeedLogin = '*';

    public function index()
    {
        $productid = input('productid/d');
        if (empty($productid)) {
            $this->error('productid不能为空');
        }
//        $address = TermModel::order('id','DESC')
//            ->where('productid',$productid)
//            ->field('id,productid,term,num')
//            ->select();
//        if (!$address){
//            $this->error('该咖啡机未开启租借期限');
//        }
        $list = DetailModel::with(['child'])
            ->where('id',$productid)
            ->order('sales DESC,money DESC')
            ->field('id,image,profilee,name,money,deposit')
            ->select();
        if (!$list){
            $this->error('不存在');
        }
        $this->success('查询成功',[

            'list' => $list,
//            'address' => $address,
        ]);
    }

    public function list()
    {
        $productid = input('productid/d');
        if (empty($productid)) {
            $this->error('productid不能为空');
        }
        $address = TermModel::order('id','DESC')
            ->where('productid',$productid)
            ->field('id,productid,term,num')
            ->select();
        if (!$address){
            $this->error('该咖啡机未开启租借期限');
        }
        $this->success('查询成功',[

            'list' => $address,
        ]);

    }


}